<%-- 
    Document   : lab
    Created on : 2019-7-13, 20:54:37
    Author     : dusin
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>教学助手</title>
        <link rel="stylesheet" href="../../js/jquery/themes/default/easyui.css" type="text/css" />
        <link rel="stylesheet" href="../../js/jquery/themes/icon.css" type="text/css" />
        <script type="text/javascript" src="../../js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="../../js/jquery/jquery.easyui.min.js"></script>        
        <script language="JavaScript">
             function formatterAttendanceStatus(value, row){
                if(value==0){   //这里value的类型是String，不能用‘===’三等号
                    return  '<span style="color:red;">'+'✖'+'</span>';                 
                }else if(value==1){
                   return '<span style="color:green;">'+'✔'+'</span>'; 
                }else if(value==2){
                   return '<span style="color:red;">'+'退回修改'+'</span>';
                }else if(value==3){
                   return '<span style="color:green;">'+'✔'+'</span>';
                }else{
                    return value;
                }
            }
            $(document).ready(function() {                
                $("#upload-lab").click(function() {
                        $('#dlg-lab').dialog('close');
                        $('#dg-lab').datagrid('loading');
                        $("#imgWait").show();
                        var row = $('#dg-lab').datagrid('getSelected');
                        $("#fm-uploadlab").form('submit', {
                            type: "post", //提交方式    
                            dataType: 'json',
                            url: "../../servlet/student/UploadReport", //请求url
                            onSubmit:function(param){
                                param.jobId=row.id;
                                param.no = row.no;
                                param.threshold = row.threshold;
                                var v = $('#file1').textbox('getValue');
                                if(v===null||v===""){
                                    $.messager.alert({title: '提示',
                                    msg: '请选择一个文件后再上传',
                                    icon: 'info',
                                });
                                    return false;
                                }
                            },
                            success: function(data) { //提交成功的回调函数   
                                var data = eval('(' + data + ')');
                                $.messager.alert({title: '提示',
                                    msg: data.name+data.msg,
                                    icon: 'info',
                                });
                                $("#imgWait").hide();
                                $('#dlg-lab').dialog('close');
                                $('#dg-lab').datagrid('reload');
                                $('#dg-lab').datagrid('loaded');
                            },
                            error: function() {
                                alert("上传失败！");
                                $("#imgWait").hide();
                                $('#dg-lab').datagrid('loaded');
                            }
                        });
                    });
               $('#dg-lab').datagrid({
                    onSelect: function(index,row){
                        if((row.jstatus==null||row.jstatus==0)&&(row.sstatus==null||row.sstatus===0)){
                            $('#cancelLinkButton').linkbutton('disable');
                            $('#uploadLinkButton').linkbutton('enable');                            
                        }else if((row.jstatus==null||row.jstatus==0)&&row.sstatus==1){
                            $('#cancelLinkButton').linkbutton('enable');
                            $('#uploadLinkButton').linkbutton('disable');
                        }else{
                            $('#cancelLinkButton').linkbutton('disable');
                            $('#uploadLinkButton').linkbutton('disable');
                        }
                    }
                }); 
                
            });
            function refresh() {
                $('#dg-lab').datagrid('reload');    // reload the user data
            }
            function upload(){
                var row = $('#dg-lab').datagrid('getSelected');
                if(row===null){
                    $.messager.alert('提示','您还没有选择实验，请点击下面一个实验进行上传','info');
                    return;
                }
                $('#fm-uploadlab').form('clear');
                $('#lab-title').html('实验名称：《'+row.title+"》");
                $('#jobId').textbox('setValue',row.no);
                $('#jobId').hide();
                $('#dlg-lab').dialog('open').dialog('setTitle', '上传实验报告');                
            }
            function cancelUpload(){
                var row = $('#dg-lab').datagrid('getSelected');
                if(row===null){
                    $.messager.alert('提示','您还没有选择实验，请点击下面一个实验进行操作','info');
                    return;
                }
                $.messager.confirm('Confirm', '你确定取消实验'+row.no+'<'+row.title+'>上传文件吗?', function(r){
                    if (r){
                        $.ajax({url:"../../servlet/student/CancelReport",
                            data:{id:row.id,no:row.no,filename:row.path},
                            success:function(result){
                                $('#dg-lab').datagrid('reload');
                                $.messager.show({ title:'提示', msg:'您已删除实验《'+row.title+'》实验报告', timeout:5000, showType:'slide'});
                            },
                            error:function(result){
                                $.messager.show({ title:'提示', msg:'实验报告删除失败:'+r.msg, timeout:5000, showType:'slide'});
                            }
                    });     
                    }
                });
            }
                
        </script>
    </head>
    <body>
        <table id="dg-lab" class="easyui-datagrid"  title="${courseName}实验" toolbar="#stoolbar"
               data-options="url:'../../servlet/student/CourseJobs',fitColumns:true,singleSelect:true">
            <thead>
                <tr>
                    <th data-options="field:'no',width:20">No</th>
                    <th data-options="field:'title',width:100">实验名称</th>
                    <th data-options="field:'duedate',width:100">截止日期</th>
                    <th data-options="field:'count',width:100">提交次数</th>
                    <th data-options="field:'time',width:100">上传时间</th>
                    <th data-options="field:'score',hidden:true,width:30">评分</th>
                    <th data-options="field:'sstatus',width:30,formatter:formatterAttendanceStatus">提交</th>
                    <th data-options="field:'snote',width:200">评语</th> 
                    <th data-options="field:'jnote',width:200">备注</th> 
                 
                </tr>
            </thead>
        </table>
        <div id="stoolbar">
            <a href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="refresh()">刷新</a>
            <a href="#" id="uploadLinkButton" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="upload()">上传</a>
            <a href="#" id="cancelLinkButton" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="cancelUpload()">删除上传</a>            
        </div>
        
        <div id="dlg-lab" class="easyui-dialog" style="width:500px;height:280px;padding:10px 20px"
             closed="true" buttons="#dlg-buttons-lab">
            <div id="lab-title" class="ftitle" style="color:blue;font-size: 20px"></div>
            <div style="color:red">（只接受word文档，请仔细核对文件内容，不要传错！）</div>
            <br/>
            <form id="fm-uploadlab" method="post" enctype="multipart/form-data">                
                <div style="margin-bottom:20px">
                    <input class="easyui-textbox" id="jobId" name="jobNo" type="text" hidden="true" data-options="readonly:true"/>
                    <input class="easyui-filebox" name="file1" id="file1"
                           data-options="prompt:'选中文件...',buttonText:'选择文件'" 
                           style="width:100%" required="true" 
                           accept="application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document">
                </div>
                <img src="../../img/gif/wait.gif"  width="150" height="150"
                  style="display:none" />
            </form>
        </div>
        <div id="dlg-buttons-lab">
            <a href="#" id="upload-lab" class="easyui-linkbutton" iconCls="icon-ok" >上传</a>
            <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg-lab').dialog('close')">取消</a>
        </div>
    </body>
</html>
